import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { OrderPackagePersonalizationApi } from '#/api/spa/order/packagepersonalization';

import { z } from '#/adapter/form';
import {
    DICT_TYPE,
    getDictOptions,
    getRangePickerDefaultProps,
} from '#/utils';
import {DICT_SPA_TYPE} from "#/utils/dictSpa";

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'orderPackageId',
      label: '关联spa_order_package表ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入关联spa_order_package表ID',
      },
    },
    {
      fieldName: 'personalizationId',
      label: '关联spa_package_personalization表ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入关联spa_package_personalization表ID',
      },
    },
    {
      fieldName: 'optionKey',
      label: '选项键',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入选项键',
      },
    },
    {
      fieldName: 'optionValue',
      label: '选项值',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入选项值',
      },
    },
    {
      fieldName: 'optionLabel',
      label: '选项标签',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入选项标签',
      },
    },
    {
      fieldName: 'optionPrice',
      label: '选项价格',
      component: 'Input',
      componentProps: {
        placeholder: '请输入选项价格',
      },
    },
    {
      fieldName: 'isSelected',
      label: '是否已选择',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'selectionTime',
      label: '选择时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限引用',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'orderPackageId',
      label: '关联spa_order_package表ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入关联spa_order_package表ID',
      },
    },
    {
      fieldName: 'personalizationId',
      label: '关联spa_package_personalization表ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入关联spa_package_personalization表ID',
      },
    },
    {
      fieldName: 'optionKey',
      label: '选项键',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入选项键',
      },
    },
    {
      fieldName: 'optionValue',
      label: '选项值',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入选项值',
      },
    },
    {
      fieldName: 'optionLabel',
      label: '选项标签',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入选项标签',
      },
    },
    {
      fieldName: 'optionPrice',
      label: '选项价格',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入选项价格',
      },
    },
    {
      fieldName: 'isSelected',
      label: '是否已选择',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        placeholder: '请选择是否已选择',
      },
    },
    {
      fieldName: 'selectionTime',
      label: '选择时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限引用',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<OrderPackagePersonalizationApi.OrderPackagePersonalization>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,

    },
    {
      field: 'orderPackageId',
      title: '关联spa_order_package表ID',
      minWidth: 120,

    },
    {
      field: 'personalizationId',
      title: '关联spa_package_personalization表ID',
      minWidth: 120,

    },
    {
      field: 'optionKey',
      title: '选项键',
      minWidth: 120,

    },
    {
      field: 'optionValue',
      title: '选项值',
      minWidth: 120,

    },
    {
      field: 'optionLabel',
      title: '选项标签',
      minWidth: 120,

    },
    {
      field: 'optionPrice',
      title: '选项价格',
      minWidth: 120,

    },
    {
      field: 'isSelected',
      title: '是否已选择',
      minWidth: 120,

    },
    {
      field: 'selectionTime',
      title: '选择时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'scope',
      title: '权限范围',
      minWidth: 120,

    },
    {
      field: 'scoperef',
      title: '权限引用',
      minWidth: 120,

    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

